
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>@PostConstruct和@PreDestroy的用途？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>@PostConstruct和@PreDestroy的用途？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">在 Java 中，`@PostConstruct` 和 `@PreDestroy` 这两个注解的核心作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它们是用于管理 Bean 生命周期的注解，通常在 Spring 框架中使用。它们提供了一种机制，允许在 Bean 的创建（初始化）和销毁时执行特定的自定义操作。</div>
          </div>
          <div class="card-source">来源: 文档开篇部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">`@PostConstruct` 注解标记的方法在 Bean 生命周期的哪个具体时间点被调用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">被 `@PostConstruct` 注解标记的方法会在依赖注入完成后、Bean 的初始化阶段之后被 Spring 容器自动调用。</div>
          </div>
          <div class="card-source">来源: 文档中「@PostConstruct」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">请列举一些适合使用 `@PostConstruct` 注解的典型初始化场景。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">典型的使用场景包括：加载配置信息、初始化系统资源、或检查必要的依赖关系是否已经就绪等需要在 Bean 完全初始化后执行的操作。</div>
          </div>
          <div class="card-source">来源: 文档中「@PostConstruct」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">`@PreDestroy` 注解标记的方法在 Bean 生命周期的哪个阶段执行？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">被 `@PreDestroy` 注解标记的方法会在 Bean 被容器销毁之前自动调用，用于执行清理任务。</div>
          </div>
          <div class="card-source">来源: 文档中「@PreDestroy」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在哪些场景下应该使用 `@PreDestroy` 注解？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当需要在 Bean 被销毁前执行清理操作时，可以使用 `@PreDestroy`。例如：释放文件句柄、关闭数据库或网络连接、保存当前状态等。</div>
          </div>
          <div class="card-source">来源: 文档中「@PreDestroy」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">简要说明 `@PostConstruct` 和 `@PreDestroy` 分别解决了 Bean 生命周期中的什么问题？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`@PostConstruct` 解决了在所有依赖注入完成后执行特定初始化逻辑的问题；而 `@PreDestroy` 解决了在 Bean 被销毁前执行确定性清理操作的问题，从而确保资源的正确释放。</div>
          </div>
          <div class="card-source">来源: 文档中「@PostConstruct」和「@PreDestroy」部分</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
